import axios from 'axios'

const baseURL = 'http://172.16.91.81:9090'
// const baseURL = 'https://test.derkee.com/' // uat

// 创建axios实例
const request = axios.create({
  baseURL: baseURL, // 使用代理路径，实际地址在nuxt.config.ts中配置
  timeout: 50000, // 请求超时时间
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  }
})

// 封装GET请求
export async function get(url, params) {
  return request.get(url, { params }).then(res => res.data)
}

// 封装POST请求
export async function post(url, data) {
  return request.post(url, data).then(res => res.data)
}

// 封装PUT请求
export async function put(url, data) {
  return request.put(url, data).then(res => res.data)
}

// 封装DELETE请求
export async function del(url, params) {
  return request.delete(url, { params }).then(res => res.data)
}

// 封装PATCH请求
export async function patch(url, data) {
  return request.patch(url, data).then(res => res.data)
}

// 封装HEAD请求
export async function head(url, params) {
  return request.head(url, { params }).then(res => res.data)
}

// 封装OPTIONS请求
export async function options(url, params) {
  return request.options(url, { params }).then(res => res.data)
}

export default request